home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / SourceCode / AdobeExamples / NX_ImportInt / ImportApp.m < prev    next >
Encoding:
Text File  |  1992-12-19  |  5.4 KB  |  267 lines

  1.  
  2. /*
  3.  * (a)  (C) 1990 by Adobe Systems Incorporated. All rights reserved.
  4.  *
  5.  * (b)  If this Sample Code is distributed as part of the Display PostScript
  6.  *    System Software Development Kit from Adobe Systems Incorporated,
  7.  *    then this copy is designated as Development Software and its use is
  8.  *    subject to the terms of the License Agreement attached to such Kit.
  9.  *
  10.  * (c)  If this Sample Code is distributed independently, then the following
  11.  *    terms apply:
  12.  *
  13.  * (d)  This file may be freely copied and redistributed as long as:
  14.  *    1) Parts (a), (d), (e) and (f) continue to be included in the file,
  15.  *    2) If the file has been modified in any way, a notice of such
  16.  *      modification is conspicuously indicated.
  17.  *
  18.  * (e)  PostScript, Display PostScript, and Adobe are registered trademarks of
  19.  *    Adobe Systems Incorporated.
  20.  * 
  21.  * (f) THE INFORMATION BELOW IS FURNISHED AS IS, IS SUBJECT TO
  22.  *    CHANGE WITHOUT NOTICE, AND SHOULD NOT BE CONSTRUED
  23.  *    AS A COMMITMENT BY ADOBE SYSTEMS INCORPORATED.
  24.  *    ADOBE SYSTEMS INCORPORATED ASSUMES NO RESPONSIBILITY
  25.  *    OR LIABILITY FOR ANY ERRORS OR INACCURACIES, MAKES NO
  26.  *    WARRANTY OF ANY KIND (EXPRESS, IMPLIED OR STATUTORY)
  27.  *    WITH RESPECT TO THIS INFORMATION, AND EXPRESSLY
  28.  *    DISCLAIMS ANY AND ALL WARRANTIES OF MERCHANTABILITY, 
  29.  *    FITNESS FOR PARTICULAR PURPOSES AND NONINFRINGEMENT
  30.  *    OF THIRD PARTY RIGHTS.
  31.  */
  32.  
  33. /*
  34. *    ImportApp.m
  35. *
  36. *    This class performs some of the global functions necessary to
  37. *    manage the application.
  38. *
  39. *    Several application wide resources are retained as
  40. *    instance variables. Examples are the hitPoint and
  41. *    upathBuffer buffers, the hitSetting value and the
  42. *    epsfContext.
  43. *
  44. *    The epsfContext is a separate context that is
  45. *    used solely for imaging included epsf files. It
  46. *    prevents any errors in the epsf files from harming
  47. *    the application's context. If errors occur when imaging
  48. *    an epsf file, the context is destroyed and a new one
  49. *    created. (See the context setting methods in this file
  50. *    as well as in GraphicEpsf.m for specific details on
  51. *    how to switch the contexts.) 
  52. *
  53. *    Version:    2.0
  54. *    Author:    Ken Fromm
  55. *    History:
  56. *            03-07-91        Added this comment.
  57. */
  58.  
  59. #import "ImportApp.h"
  60. #import "Document.h"
  61. #import "SaveAsPanel.h"
  62.  
  63. #import "DrawingViewWraps.h"
  64.  
  65. #import <appkit/Matrix.h>
  66. #import <appkit/NXCursor.h>
  67. #import <appkit/NXImage.h>
  68. #import <appkit/Window.h>
  69. #import <appkit/defaults.h>
  70. #import <appkit/nextstd.h>
  71.  
  72. char    ControlFont[ ] = "ControlPointsFont";
  73.  
  74. @implementation ImportApp
  75.  
  76. + new
  77. {
  78.     self = [super new];
  79.  
  80.     [self  setAutoupdate:YES];
  81.     [self  initializeSelf];
  82.  
  83.     return self;
  84. }
  85.  
  86. - free
  87. {
  88.     if (upathBuffer.pts)
  89.         NX_FREE(upathBuffer.pts);
  90.     if (upathBuffer.ops)
  91.         NX_FREE(upathBuffer.ops);
  92.     if (hitPoint.pts)
  93.         NX_FREE(hitPoint.pts);
  94.     if (hitPoint.ops)
  95.         NX_FREE(hitPoint.ops);
  96.  
  97.     return [super free];
  98. }
  99.  
  100. /*
  101. *     Allocate a buffer for use by any drawing view to send
  102. *     data to the PostScript server.
  103. *
  104. *    Allocate another buffer for use by any drawing view to
  105. *    use as the hitdetection userpath. Initialize the description
  106. *    since most of the components will remain the same.
  107. */
  108. - initializeSelf
  109. {
  110.     int        i;
  111.  
  112.     contextFlag = YES;
  113.  
  114.     PSWDefineFont(ControlFont);
  115.  
  116.     NX_MALLOC(upathBuffer.pts, float, PTS_BUFFER);
  117.     NX_MALLOC(upathBuffer.ops, char, OPS_BUFFER);
  118.  
  119.     NX_MALLOC(hitPoint.pts, float, PTS_HITPOINT);
  120.     NX_MALLOC(hitPoint.ops, char, OPS_HITPOINT);
  121.  
  122.     for (i = 0; i < PTS_HITPOINT; i++)
  123.         hitPoint.pts[i] = 0;            
  124.     hitPoint.num_pts = i;
  125.      
  126.     i = 0;
  127.     hitPoint.ops[i++] = dps_setbbox;
  128.     hitPoint.ops[i++] = dps_moveto;
  129.     hitPoint.ops[i++] = dps_rlineto;
  130.     hitPoint.ops[i++] = dps_rlineto;
  131.     hitPoint.ops[i++] = dps_rlineto;
  132.     hitPoint.ops[i++] = dps_closepath;
  133.     hitPoint.num_ops = i;
  134.  
  135.     return self;
  136. }
  137.  
  138. - setSaveAccessory:anObject
  139. {
  140.     id        savepanel;
  141.  
  142.     savepanel = [SaveAsPanel  new];
  143.  
  144.     [savepanel  setAccessoryView:anObject];
  145.     [savepanel  setSaveTo];
  146.  
  147.     return self;
  148. }
  149.  
  150. - setContextFlag:sender
  151. {
  152.     if (!contextFlag)
  153.         [[sender selectedCell] setTitle:"Separate Context On"];
  154.     else
  155.         [[sender selectedCell] setTitle:"Separate Context Off"];
  156.  
  157.     contextFlag = !contextFlag;
  158.     
  159.     return self;
  160. }
  161.  
  162. - (BOOL) contextFlag
  163. {
  164.     return contextFlag;
  165. }
  166.  
  167. - setShowEpsfFlag:sender
  168. {
  169.     if (!showEpsfFlag)
  170.         [[sender selectedCell] setTitle:"Show Epsf On"];
  171.     else
  172.         [[sender selectedCell] setTitle:"Show Epsf Off"];
  173.  
  174.     showEpsfFlag = !showEpsfFlag;
  175.  
  176.     return self;
  177. }
  178.  
  179. - (BOOL) showEpsfFlag
  180. {
  181.     return showEpsfFlag;
  182. }
  183.  
  184. - setTracingFlag:sender
  185. {
  186.     if (!tracingFlag)
  187.         [[sender selectedCell] setTitle:"Trace On"];
  188.     else
  189.         [[sender selectedCell] setTitle:"Trace Off"];
  190.  
  191.     tracingFlag = !tracingFlag;
  192.     
  193.     return self;
  194. }
  195.  
  196. - (BOOL) tracingFlag
  197. {
  198.     return tracingFlag;
  199. }
  200.  
  201. - (UPath *) hitPoint;
  202. {
  203.     return &hitPoint;
  204. }
  205.  
  206. - (UPath *) upathBuffer;
  207. {
  208.     return &upathBuffer;
  209. }
  210.  
  211. - resourcePanel
  212. {
  213.     if (!resourcePanel)
  214.         [NXApp  loadNibSection:"ResourcePanel.nib"  owner:self  withNames:NO];
  215.  
  216.     return resourcePanel;
  217. }
  218.  
  219. - cursor
  220. {
  221.     id        imageId, cursorId;
  222.  
  223.     NXPoint    spot;
  224.  
  225.     if (operation == OP_IMPORT)
  226.     {
  227.         if (!importId)
  228.         {
  229.             imageId = [NXImage  newFromSection:"cursorImport.tiff"];
  230.             importId = [NXCursor  newFromImage:imageId];
  231.             spot.x = 2.0;  spot.y = 1.0;
  232.             [importId setHotSpot:&spot];
  233.         }
  234.         cursorId = importId;
  235.     }
  236.     else
  237.         cursorId = NXArrow;
  238.  
  239.     return cursorId;
  240. }
  241.  
  242. - setOperation:(int) op
  243. {
  244.     operation = op;
  245.     [[documentId  window]  invalidateCursorRectsForView:[[documentId  window] contentView]];
  246.  
  247.     return self;
  248. }
  249.  
  250. - (int) operation
  251. {
  252.     return operation;
  253. }
  254.  
  255. /*
  256.  *    Application delegate methods.
  257.  */
  258. - appDidInit:sender
  259. {
  260.     documentId = [Document  new];    
  261.  
  262.     return self;
  263. }
  264.  
  265. @end
  266.  
  267.